<?php

namespace App\Models;

use App\Observers\CommunityObserver;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Community extends Model
{
    use HasFactory;
    use SoftDeletes;
    protected $guarded=[];
    protected $table='zfm_communitys';
     /**
     * 小区信息展示
     * @return mixed
     */
    public static function list($paginate){
        return self::select('id','name','loaction','logo','clicks','text')->paginate($paginate);
    }
    /**
     * 小区信息查找
     * @param $where
     * @return mixed
     */
    public static function Seek($field,$where){
        return self::where($field,'like',"%$where%")->get();
    }
     /**
     * 小区多条件信息查找
     * @param $where
     * @return mixed
     */
    public static function wheres($where,$paginate){
        return self::where($where)->paginate($paginate);
    }
    /**
     * 小区信息删除
     */
    public static function del($id,$fangId){
        return self::where([$id=>$fangId])
            ->delete();
    }
    /**
     * 小区详情信息
     */
    public static function detail($field,$where){
        return self::where($field,$where)->first();
    }
    /**
     * 小区信息修改
     */
    public static function change($field,$ID,$SecondaryMessageUpdated){
        $update= self::where($field,$ID,$ID)->first();
        return $update->fill($SecondaryMessageUpdated)
        ->save();
    }
    //观察者
    public static function boot()
    {
        parent::boot();
        self::observe(CommunityObserver::class);
    }
}
